﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Issues.RaidAnEnemyTerritoryIssueBehavior
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Issues
{
  public class RaidAnEnemyTerritoryIssueBehavior : CampaignBehaviorBase
  {
    private const int BaseRewardGold = 15000;
    private const int ExtraRewardMultiplier = 3000;
    private const int TargetRaidVillageCount = 3;
    private const IssueBase.IssueFrequency RaidAnEnemyTerritoryIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

    public override void RegisterEvents()
    {
      CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener((object) this, new Action<Hero>(this.OnCheckForIssue));
    }

    public void OnCheckForIssue(Hero hero)
    {
      if (this.ConditionsHold(hero))
        Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof (RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue), IssueBase.IssueFrequency.VeryCommon));
      else
        Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof (RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue), IssueBase.IssueFrequency.VeryCommon));
    }

    private bool ConditionsHold(Hero issueGiver)
    {
      return issueGiver.IsLord && issueGiver.MapFaction.IsKingdomFaction && issueGiver == ((Kingdom) issueGiver.MapFaction).Leader && issueGiver.GetTraitLevel(DefaultTraits.Mercy) <= 0 && issueGiver.GetTraitLevel(DefaultTraits.Calculating) >= 0 && this.GetAtWarWithFactionCount(issueGiver) >= 1;
    }

    private int GetAtWarWithFactionCount(Hero issueGiver)
    {
      int withFactionCount = 0;
      foreach (Kingdom other in (List<Kingdom>) Kingdom.All)
      {
        if (issueGiver.MapFaction != other && issueGiver.MapFaction.IsAtWarWith((IFaction) other) && other.Settlements.Count > 1)
          ++withFactionCount;
      }
      return withFactionCount;
    }

    private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
    {
      return (IssueBase) new RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue(issueOwner);
    }

    public override void SyncData(IDataStore dataStore)
    {
    }

    public class RaidAnEnemyTerritoryIssue : IssueBase
    {
      private const int IssueDurationInDays = 60;
      private const int RelationLimitWithPlayer = -10;
      [SaveableField(10)]
      private readonly Kingdom _enemyKingdom;

      internal static void AutoGeneratedStaticCollectObjectsRaidAnEnemyTerritoryIssue(
        object o,
        List<object> collectedObjects)
      {
        ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        base.AutoGeneratedInstanceCollectObjects(collectedObjects);
        collectedObjects.Add((object) this._enemyKingdom);
      }

      internal static object AutoGeneratedGetMemberValue_enemyKingdom(object o)
      {
        return (object) ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue) o)._enemyKingdom;
      }

      public override TextObject IssueBriefByIssueGiver
      {
        get
        {
          TextObject parent = new TextObject("{=CrzFdo2H}Yes. It's about the war with the {ENEMYFACTION_INFORMALNAME}. [ib:hip][if:convo_excited]We need to tie up some of their forces. A relatively small force moving quickly through their lands and raiding their villages should be a good distraction. Their lords will need to chase the raiders and won't be able to threaten us elsewhere. You seem to be the right {?PLAYER.GENDER}warrior{?}man{\\?} for the job. What do you say? You'll have my gratitude and you'll be well rewarded if you succeed.");
          if (this.IssueOwner.GetTraitLevel(DefaultTraits.Mercy) + this.IssueOwner.GetTraitLevel(DefaultTraits.Honor) >= 0)
            parent = new TextObject("{=OlIWwLbP}Yes. It's about the war with the {ENEMYFACTION_INFORMALNAME}. [ib:closed][if:convo_pondering]We need to tie up some of their forces, and the easiest way to do that would be to raid their villages. It's a cruel business and will be hard on the common folk, but their lords will need to chase the raiders and it will prevent them from doing the same to us. If you take this on, I shall reward you if you succeed.");
          parent.SetTextVariable("ENEMYFACTION_INFORMALNAME", this._enemyKingdom.InformalName);
          StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, parent);
          return parent;
        }
      }

      public override TextObject IssueAcceptByPlayer
      {
        get
        {
          TextObject parent = new TextObject("{=bLfXzCyc}I'm at your service my {?ISSUE_OWNER.GENDER}lady{?}lord{\\?}. Just tell me the details.");
          StringHelpers.SetCharacterProperties("ISSUE_OWNER", this.IssueOwner.CharacterObject, parent);
          return parent;
        }
      }

      public override TextObject IssueQuestSolutionExplanationByIssueGiver
      {
        get
        {
          TextObject explanationByIssueGiver = new TextObject("{=aRfMtTUT}Good. See if you can hit {NUMBER_OF_TARGET_VILLAGE} villages. They won't be able to ignore that kind of damage. I'll give you {BASE_REWARD}{GOLD_ICON} for doing that, and {EXTRA_REWARD}{GOLD_ICON} more for every extra one that you raid. Agreed?[if:convo_mocking_revenge]");
          if (this.IssueOwner.GetTraitLevel(DefaultTraits.Mercy) + this.IssueOwner.GetTraitLevel(DefaultTraits.Honor) > 0)
            explanationByIssueGiver = new TextObject("{=AEVIa5sQ}So be it. See if you can hit {NUMBER_OF_TARGET_VILLAGE} villages. [if:convo_stern]They won't be able to ignore that, and it will put a dent in their revenues. I'll give you {BASE_REWARD}{GOLD_ICON} for doing that, and {EXTRA_REWARD}{GOLD_ICON} more for every extra one that you raid. Do you agree?");
          explanationByIssueGiver.SetTextVariable("NUMBER_OF_TARGET_VILLAGE", 3);
          explanationByIssueGiver.SetTextVariable("BASE_REWARD", 15000);
          explanationByIssueGiver.SetTextVariable("EXTRA_REWARD", 3000);
          return explanationByIssueGiver;
        }
      }

      public override TextObject IssueQuestSolutionAcceptByPlayer
      {
        get
        {
          TextObject parent = new TextObject("{=nrRvyKgL}I'll strike into their territory as you command, my {?ISSUE_OWNER.GENDER}lady{?}lord{\\?}.");
          StringHelpers.SetCharacterProperties("ISSUE_OWNER", this.IssueOwner.CharacterObject, parent);
          return parent;
        }
      }

      public override bool IsThereAlternativeSolution => false;

      public override bool IsThereLordSolution => false;

      public override TextObject Title => new TextObject("{=DSlhMswt}Raid an Enemy Territory");

      public override TextObject Description
      {
        get
        {
          TextObject parent = new TextObject("{=JEuZoV1E}{ISSUE_OWNER.LINK} asks you to raid enemy villages to distract enemy war parties.");
          StringHelpers.SetCharacterProperties("ISSUE_OWNER", this.IssueOwner.CharacterObject, parent);
          return parent;
        }
      }

      public RaidAnEnemyTerritoryIssue(Hero issueGiver)
        : base(issueGiver, CampaignTime.DaysFromNow(60f))
      {
        this._enemyKingdom = Kingdom.All.Where<Kingdom>((Func<Kingdom, bool>) (k => k.IsAtWarWith(this.IssueOwner.MapFaction))).GetRandomElementInefficiently<Kingdom>();
      }

      protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
      {
        return issueEffect == DefaultIssueEffects.ClanInfluence ? -0.1f : 0.0f;
      }

      protected override void OnGameLoad()
      {
      }

      protected override void HourlyTick()
      {
      }

      protected override QuestBase GenerateIssueQuest(string questId)
      {
        return (QuestBase) new RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest(questId, this.IssueOwner, CampaignTime.DaysFromNow(60f), this._enemyKingdom);
      }

      public override IssueBase.IssueFrequency GetFrequency()
      {
        return IssueBase.IssueFrequency.VeryCommon;
      }

      protected override bool CanPlayerTakeQuestConditions(
        Hero issueGiver,
        out IssueBase.PreconditionFlags flag,
        out Hero relationHero,
        out SkillObject skill)
      {
        flag = IssueBase.PreconditionFlags.None;
        relationHero = (Hero) null;
        skill = (SkillObject) null;
        if ((double) issueGiver.GetRelationWithPlayer() < -10.0)
        {
          relationHero = issueGiver;
          flag |= IssueBase.PreconditionFlags.Relation;
        }
        if (Clan.PlayerClan.Kingdom != issueGiver.MapFaction)
          flag |= IssueBase.PreconditionFlags.NotInSameFaction;
        return flag == IssueBase.PreconditionFlags.None;
      }

      public override bool IssueStayAliveConditions()
      {
        return this._enemyKingdom.IsAtWarWith(this.IssueOwner.MapFaction) && !this._enemyKingdom.IsEliminated && this.IssueOwner.MapFaction.IsKingdomFaction;
      }

      protected override void CompleteIssueWithTimedOutConsequences()
      {
      }
    }

    public class RaidAnEnemyTerritoryQuest : QuestBase
    {
      private const int RenownBonus = 5;
      private const int HonorXpBonus = 10;
      private const int InfluenceBonus = 20;
      private const int RelationBonusWithQuestGiver = 10;
      private const int HonorXpPenalty = -10;
      private const int RelationPenaltyWithQuestGiver = -5;
      [SaveableField(10)]
      private JournalLog _raidedVillagesTrackLog;
      [SaveableField(20)]
      private readonly Kingdom _enemyKingdom;
      [SaveableField(30)]
      private readonly List<Settlement> _raidedVillages;

      internal static void AutoGeneratedStaticCollectObjectsRaidAnEnemyTerritoryQuest(
        object o,
        List<object> collectedObjects)
      {
        ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
      }

      protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
      {
        base.AutoGeneratedInstanceCollectObjects(collectedObjects);
        collectedObjects.Add((object) this._raidedVillagesTrackLog);
        collectedObjects.Add((object) this._enemyKingdom);
        collectedObjects.Add((object) this._raidedVillages);
      }

      internal static object AutoGeneratedGetMemberValue_raidedVillagesTrackLog(object o)
      {
        return (object) ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest) o)._raidedVillagesTrackLog;
      }

      internal static object AutoGeneratedGetMemberValue_enemyKingdom(object o)
      {
        return (object) ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest) o)._enemyKingdom;
      }

      internal static object AutoGeneratedGetMemberValue_raidedVillages(object o)
      {
        return (object) ((RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest) o)._raidedVillages;
      }

      public override TextObject Title => new TextObject("{=DSlhMswt}Raid an Enemy Territory");

      public override bool IsRemainingTimeHidden => false;

      private TextObject _questAcceptedByPlayerLog
      {
        get
        {
          TextObject parent = new TextObject("{=sYfvsMwN}{QUEST_GIVER.LINK} asked you to raid {NUMBER_OF_TARGET_VILLAGE} {ENEMYFACTION_INFORMALNAME} villages to distract their lords and weaken their armies. {?QUEST_GIVER.GENDER}She{?}He{\\?} offers {REWARD_GOLD}{GOLD_ICON} to thank you for your deeds.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          parent.SetTextVariable("NUMBER_OF_TARGET_VILLAGE", 3);
          parent.SetTextVariable("ENEMYFACTION_INFORMALNAME", this._enemyKingdom.InformalName);
          parent.SetTextVariable("EXTRA_REWARD", 3000);
          parent.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
          parent.SetTextVariable("REWARD_GOLD", 15000);
          return parent;
        }
      }

      private TextObject _mainHeroRaidedAllVillagesLog
      {
        get
        {
          return new TextObject("{=gMvDCnlx}You have successfully raided enemy villages and distracted enemy forces as promised.");
        }
      }

      private TextObject _mainHeroCouldNotRaidedAllVillagesLog
      {
        get
        {
          TextObject parent = new TextObject("{=nRkLFBMl}You failed to raid at least {NUMBER_OF_TARGET_VILLAGE} villages and then report back. {QUEST_GIVER.LINK} is disappointed.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject _questGiverDiedLog
      {
        get
        {
          TextObject parent = new TextObject("{=65BTaOl8}{QUEST_GIVER.LINK} died and your mission is canceled.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject _enemyIsOutOfVillagesLog
      {
        get
        {
          TextObject parent = new TextObject("{=bIDvq6wA}The enemy no longer holds any villages. {QUEST_GIVER.LINK} has canceled your mission.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject _declaredWarOnQuestGiverFactionLog
      {
        get
        {
          TextObject parent = new TextObject("{=2diuD0rT}Your clan/faction is now at war with {QUEST_GIVER.LINK}'s faction. Your agreement with {QUEST_GIVER.LINK} has been canceled.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject _playerDeclaredWarQuestLogText
      {
        get
        {
          TextObject parent = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          return parent;
        }
      }

      private TextObject _declaredPeaceBetweenQuestGiverAndEnemyFactionsLog
      {
        get
        {
          TextObject parent = new TextObject("{=AXsbnTBb}{QUEST_GIVER.LINK} has made peace with the {ENEMYFACTION_INFORMALNAME}. Your agreement with {QUEST_GIVER.LINK} has been canceled.");
          StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject, parent);
          parent.SetTextVariable("ENEMYFACTION_INFORMALNAME", this._enemyKingdom.InformalName);
          return parent;
        }
      }

      private TextObject _factionLeftLog
      {
        get
        {
          TextObject to = new TextObject("{=c63DWZhr}You left {FACTION}. Your agreement with {QUEST_GIVER.LINK} is terminated.");
          to.SetTextVariable("FACTION", this.QuestGiver.MapFaction.EncyclopediaLinkWithName);
          to.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
          return to;
        }
      }

      public RaidAnEnemyTerritoryQuest(
        string questId,
        Hero questGiver,
        CampaignTime duration,
        Kingdom enemyKingdom)
        : base(questId, questGiver, duration, 15000)
      {
        this._enemyKingdom = enemyKingdom;
        this._raidedVillages = new List<Settlement>();
        this.SetDialogs();
        this.InitializeQuestOnCreation();
      }

      protected override void InitializeQuestOnGameLoad() => this.SetDialogs();

      protected override void HourlyTick()
      {
      }

      protected override void OnTimedOut()
      {
        if (this._raidedVillages.Count >= 3)
          this.MainHeroRaidedAllVillages();
        else
          this.MainHeroCouldNotRaidedAllVillages();
      }

      protected override void OnBeforeTimedOut(
        ref bool completeWithSuccess,
        ref bool doNotResolveTheQuest)
      {
        if (this._raidedVillages.Count < 3)
          return;
        completeWithSuccess = true;
      }

      protected override void RegisterEvents()
      {
        base.RegisterEvents();
        CampaignEvents.DailyTickEvent.AddNonSerializedListener((object) this, new Action(this.DailyTick));
        CampaignEvents.RaidCompletedEvent.AddNonSerializedListener((object) this, new Action<BattleSideEnum, RaidEventComponent>(this.OnRaidCompleted));
        CampaignEvents.HeroKilledEvent.AddNonSerializedListener((object) this, new Action<Hero, Hero, KillCharacterAction.KillCharacterActionDetail, bool>(this.OnHeroKilled));
        CampaignEvents.OnSettlementOwnerChangedEvent.AddNonSerializedListener((object) this, new Action<Settlement, bool, Hero, Hero, Hero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail>(this.OnSettlementOwnerChanged));
        CampaignEvents.WarDeclared.AddNonSerializedListener((object) this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
        CampaignEvents.MakePeace.AddNonSerializedListener((object) this, new Action<IFaction, IFaction, MakePeaceAction.MakePeaceDetail>(this.OnMakePeace));
        CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener((object) this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
      }

      private void OnClanChangedKingdom(
        Clan clan,
        Kingdom oldKingdom,
        Kingdom newKingdom,
        ChangeKingdomAction.ChangeKingdomActionDetail detail,
        bool showNotification = true)
      {
        if (clan != Clan.PlayerClan || oldKingdom != this.QuestGiver.MapFaction)
          return;
        this.FactionLeft();
      }

      private void DailyTick()
      {
        if (!this.QuestDueTime.IsPast || this._raidedVillages.Count < 3)
          return;
        this.MainHeroRaidedAllVillages();
      }

      private void OnRaidCompleted(BattleSideEnum winnerSide, RaidEventComponent raidEvent)
      {
        MapEvent mapEvent = raidEvent.MapEvent;
        if (!mapEvent.IsRaid || !mapEvent.IsPlayerMapEvent || !mapEvent.MapEventSettlement.IsVillage || mapEvent.PlayerSide != winnerSide || this._raidedVillages.Contains(mapEvent.MapEventSettlement))
          return;
        this._raidedVillages.Add(mapEvent.MapEventSettlement);
        this._raidedVillagesTrackLog.UpdateCurrentProgress(this._raidedVillages.Count);
        if (this._raidedVillages.Count < 3)
          return;
        TextObject textObject = new TextObject("{=VM9xDun7}You have successfully raided target villages. Go back to {QUEST_GIVER.LINK} to get your reward.");
        textObject.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
        MBInformationManager.AddQuickInformation(textObject);
      }

      private void OnHeroKilled(
        Hero victim,
        Hero killer,
        KillCharacterAction.KillCharacterActionDetail detail,
        bool showNotification = true)
      {
        if (victim != this.QuestGiver)
          return;
        if (this._raidedVillages.Count < 3)
          this.QuestGiverDied();
        else
          this.MainHeroRaidedAllVillages();
      }

      private void OnSettlementOwnerChanged(
        Settlement settlement,
        bool openToClaim,
        Hero newOwner,
        Hero oldOwner,
        Hero capturerHero,
        ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
      {
        if (oldOwner.MapFaction != this._enemyKingdom || this._enemyKingdom.Settlements.Count >= 3 - this._raidedVillages.Count)
          return;
        if (this._raidedVillages.Count < 3)
          this.EnemyIsOutOfVillages();
        else
          this.MainHeroRaidedAllVillages();
      }

      private void OnWarDeclared(
        IFaction faction1,
        IFaction faction2,
        DeclareWarAction.DeclareWarDetail detail)
      {
        if ((faction1 != this.QuestGiver.MapFaction || faction2 != Clan.PlayerClan) && (faction1 != Clan.PlayerClan || faction2 != this.QuestGiver.MapFaction))
          return;
        if (this._raidedVillages.Count < 3)
          QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest((QuestBase) this, faction1, faction2, detail, this._playerDeclaredWarQuestLogText, this._declaredWarOnQuestGiverFactionLog);
        else
          this.MainHeroRaidedAllVillages();
      }

      private void OnMakePeace(
        IFaction side1Faction,
        IFaction side2Faction,
        MakePeaceAction.MakePeaceDetail detail)
      {
        if ((side1Faction != this.QuestGiver.MapFaction || side2Faction != this._enemyKingdom) && (side1Faction != this._enemyKingdom || side2Faction != this.QuestGiver.MapFaction))
          return;
        if (this._raidedVillages.Count < 3)
          this.DeclaredPeaceBetweenQuestGiverAndEnemyFactions();
        else
          this.MainHeroRaidedAllVillages();
      }

      protected override void SetDialogs()
      {
        this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start").NpcLine(new TextObject("{=R21SLyGK}Excellent. You are a brave and loyal warrior. You have my thanks.[ib:hip][if:convo_excited]")).Condition((ConversationSentence.OnConditionDelegate) (() => Hero.OneToOneConversationHero == this.QuestGiver)).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedByPlayerConsequences)).CloseDialog();
        this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss").NpcLine(new TextObject("{=eMrClHp2}Is there any progress on the task I gave you?[ib:hip][if:convo_astonished]")).Condition(new ConversationSentence.OnConditionDelegate(this.DiscussCondition)).BeginPlayerOptions().PlayerOption(new TextObject("{=XOv5B84a}Yes, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. I raided {RAIDED_VILLAGE_COUNT} villages as you commanded.")).Condition((ConversationSentence.OnConditionDelegate) (() => this._raidedVillages.Count >= 3)).NpcLine(new TextObject("{=J4yakjtP}Splendid. You have served me well. Take your well-earned reward.[ib:hip][if:convo_grateful]")).Consequence((ConversationSentence.OnConsequenceDelegate) (() =>
        {
          this.MainHeroRaidedAllVillages();
          MapEventHelper.OnConversationEnd();
        })).CloseDialog().PlayerOption(new TextObject("{=8JvcDnh6}Not yet my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. I am working on it.")).NpcLine(new TextObject("{=EuhvSsPZ}Good. Keep them busy.[if:convo_normal]")).Consequence(new ConversationSentence.OnConsequenceDelegate(MapEventHelper.OnConversationEnd)).CloseDialog().PlayerOption(new TextObject("{=pnQN6LrV}The time is not quite right, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. I don't want to ride into a trap.")).NpcLine(new TextObject("{=DXD3ag49}Well... I hope this delay is for a good reason.[ib:closed2][if:convo_thinking]")).Consequence(new ConversationSentence.OnConsequenceDelegate(MapEventHelper.OnConversationEnd)).CloseDialog().EndPlayerOptions().CloseDialog();
      }

      private void QuestAcceptedByPlayerConsequences()
      {
        this.StartQuest();
        this._raidedVillagesTrackLog = this.AddDiscreteLog(this._questAcceptedByPlayerLog, new TextObject("{=RFH1lDMj}Raided Village Count"), 0, 3);
      }

      private bool DiscussCondition()
      {
        if (Hero.OneToOneConversationHero != this.QuestGiver)
          return false;
        StringHelpers.SetCharacterProperties("QUEST_GIVER", this.QuestGiver.CharacterObject);
        MBTextManager.SetTextVariable("RAIDED_VILLAGE_COUNT", this._raidedVillages.Count);
        return true;
      }

      private void MainHeroRaidedAllVillages()
      {
        this.AddLog(this._mainHeroRaidedAllVillagesLog);
        Clan.PlayerClan.AddRenown(5f);
        TraitLevelingHelper.OnIssueSolvedThroughQuest(Hero.MainHero, new Tuple<TraitObject, int>[1]
        {
          new Tuple<TraitObject, int>(DefaultTraits.Honor, 10)
        });
        ChangeClanInfluenceAction.Apply(Clan.PlayerClan, 20f);
        this.RelationshipChangeWithQuestGiver = 10;
        GiveGoldAction.ApplyBetweenCharacters((Hero) null, Hero.MainHero, this.RewardGold);
        if (this._raidedVillages.Count > 3)
          GiveGoldAction.ApplyBetweenCharacters((Hero) null, Hero.MainHero, (this._raidedVillages.Count - 3) * 3000);
        this.CompleteQuestWithSuccess();
      }

      private void MainHeroCouldNotRaidedAllVillages()
      {
        this.AddLog(this._mainHeroCouldNotRaidedAllVillagesLog);
        TraitLevelingHelper.OnIssueSolvedThroughQuest(Hero.MainHero, new Tuple<TraitObject, int>[1]
        {
          new Tuple<TraitObject, int>(DefaultTraits.Honor, -10)
        });
        this.RelationshipChangeWithQuestGiver = -5;
      }

      private void QuestGiverDied()
      {
        this.AddLog(this._questGiverDiedLog);
        this.CompleteQuestWithCancel();
      }

      private void EnemyIsOutOfVillages()
      {
        this.AddLog(this._enemyIsOutOfVillagesLog);
        this.CompleteQuestWithCancel();
      }

      private void DeclaredPeaceBetweenQuestGiverAndEnemyFactions()
      {
        this.AddLog(this._declaredPeaceBetweenQuestGiverAndEnemyFactionsLog);
        this.CompleteQuestWithCancel();
      }

      private void FactionLeft()
      {
        this.AddLog(this._factionLeftLog);
        this.CompleteQuestWithCancel();
      }
    }

    public class RaidAnEnemyTerritoryIssueTypeDefiner : SaveableTypeDefiner
    {
      public RaidAnEnemyTerritoryIssueTypeDefiner()
        : base(586800)
      {
      }

      protected override void DefineClassTypes()
      {
        this.AddClassDefinition(typeof (RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryIssue), 1);
        this.AddClassDefinition(typeof (RaidAnEnemyTerritoryIssueBehavior.RaidAnEnemyTerritoryQuest), 2);
      }
    }
  }
}
